//用户角色Api
import {get, post, put, del} from "../utils/request";

// 分页获取角色列表 params:关键词
export function fetchList(params) {
    return get('/role/list', params)
}

//获取所有角色列表
export function listAll() {
    return get('/role/listall')
}

//根据管理员Id获取对应菜单
export function getMenuByAdminId(id) {
    return get('/role/listmenu/admin/' + id)
}

//根据角色Id获取角色菜单
export function listMenuByRole(id) {
    return get('/role/listmenu/role/' + id)
}

//获取角色资源
export function listResourceByRole(id) {
    return get('/role/listresource/' + id)
}

// 新增角色
export function createRole(info) {
    const data = {
        "adminCount": info.adminCount,
        "createTime": info.createTime,
        "description": info.description,
        "name": info.name,
        "sort": info.sort,
        "status": info.status
    }
    return post('/role/insert', data)
}

// 更新角色
export function updateRole(info) {
    const data = {
        "adminCount": info.adminCount,
        "createTime": info.createTime,
        "description": info.description,
        "name": info.name,
        "sort": info.sort,
        "status": info.status
    }
    return post('/role/update/' + info.id, data)
}

// 删除角色
export function deleteRole(id) {
    return del('/role/del/' + id)
}

// 更新角色启用状态
export function updateStatus(roleId, status) {
    return put('/role/update/status/' + roleId + '/' +status);
}

//给角色分配菜单
export function allocMenu(data) {
    return post('/role/alloc/menu', data);
}

//给角色分配资源
export function allocResource(data) {
    return post('/role/alloc/resource', data);
}